<template>
  <div class="recharge-log-container">
    <h2 class="log-title">充值明细</h2>
    <div class="recharge-log">
      <van-list v-if="rechargeLists.length>0" v-model="loading"
                :finished="finished"
                :immediate-check="false"
                error-text="请求失败，点击重新加载"
                finished-text=""
                @load="onLoad">
        <div class="log-item"
             v-for="(log, index) in rechargeLists"
             :key="index">
          <div class="log-id">充值单号：{{log.type_id}}</div>
          <div class="log-time">{{log.create_time}}</div>
          <span class="log-num">{{mSymbol.name}}{{log.change_num}}</span>
        </div>
      </van-list>
      <div v-else>
        <no-data :noData="noData"></no-data>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from 'vue'
import { List } from 'vant'
Vue.use(List)

import { rechargeList } from '@/api/user/member/memberApi'
import noData from '@/components/noData/index'
import { mapGetters } from 'vuex'
export default Vue.extend({
  name: 'index',
  components: {
    noData
  },
  data() {
    return {
      noData: {
        width: '159px',
        txtMarginTop: '-30px',
        img: 'https://img.wifenxiao.com/h5-wfx/images/user/no_tx_log.png',
        text: '暂无充值记录'
      },
      loading: false,
      finished: false,
      rechargeLists: [],
      postData: {
        p: 1
      }
    }
  },
  methods: {
    onLoad() {
      this.rechargeListFn()
    },
    /*
     * 充值记录
     */
    rechargeListFn() {
      if (this.finished) return false
      this.loading = true
      this.$loadingWrap.show()
      const param = Object.assign(this.postData, {}, true)
      rechargeList(param).then(res => {
        this.$loadingWrap.close()
        this.loading = false
        if (res.status == 1) {
          const list = res.data.list
          this.$emit('getRechargeData', res.data)
          this.rechargeLists = this.rechargeLists.concat(list)
          this.postData.p++
          if (list.length <= 0) {
            this.finished = true
          }
        }
      })
    }
  },
  created() {
    this.rechargeListFn()
  },
  computed: {
    // 获取自定义符号
    ...mapGetters(['mSymbol'])
  }
})
</script>

<style lang="scss">
.recharge-log-container {
  margin: 20px 0 0;
  background: #fff;
  padding: 30px;
  .log-title {
    height: auto;
    margin: 0;
    line-height: 50px;
    font-size: 32px;
    font-weight:bold;
    color: #333;
    position: relative;
    padding-left: 20px;
    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 50%;
      transform: translateY(-50%);
      width: 5px;
      height: 28px;
      background: rgba(243, 21, 43, 1);
    }
  }
  .log-item {
    position: relative;
    border-bottom: 1px solid #ededed;
    padding: 20px 0;
    line-height: 52px;
    &:last-child {
      border-bottom: 0;
    }
    .log-id {
      width: 85%;
      font-size: 28px;
    }
    .log-time {
      width: 85%;
      font-size: 24px;
      color: #999999;
    }
    .log-num {
      position: absolute;
      right: 0;
      top: 50px;
      color: #fd2049;
      line-height: 1;
      font-size: 32px;
      font-weight: bold;
    }
  }
}
</style>
